package test;

import java.sql.SQLOutput;
import java.util.Scanner;

public class Kuaican {
    public static void main(String[] args) {
        int len=4;
        Scanner input = new Scanner(System.in);
        String[] names = new String[len]; // 保存订餐人名称
        String[] dishMegs = new String[len]; // 保存菜品名及份数
        int[] times = new int[len]; // 保存送餐时间
        String[] addresses = new String[len]; // 保存送餐地址
        int[] states = new int[len]; // 保存订单状态： 0：已预订 1：已完成64
        double[] sumPrices = new double[len]; // 保存订单的总金额
        String [] caiName ={"红烧带鱼","鱼香肉丝","时令鲜蔬"};
        double [] caiMoney ={38.0,20.0,10.0};
        int []like = new int[3];
        System.out.println("欢迎使用“吃货联盟订餐系统”");
        while (true) {
            System.out.println("******************************");
            System.out.println("1.我要订餐\n2.查看餐袋\n3.签收订单\n4.删除订单\n5.我要点赞\n6.退出系统");
            System.out.println("******************************");
            System.out.print("请输入你的选择：");
            int choose = input.nextInt();
            if (choose<1||choose>6)continue;
            if (choose == 1) {
                System.out.println("***我要订餐***");
                System.out.print("请输入订餐人姓名：");
                String name = input.next();

                for (int i = 0; i < names.length; i++) {
                    if (names[names.length-1] != null){
                        System.out.println("订单已达最高上线，请前往删除订单");
                        return;
                    }
                    if (names[i] ==null){
                        names[i] = name;
                        states[i] = 0;
                        System.out.print("请输入地址");
                        addresses[i] = input.next();
                        break;
                    }
                }

                System.out.println("序号\t菜名\t单价\t点赞数");
                for (int i = 0; i < caiName.length; i++) {
                    System.out.println((i+1)+caiName[i]+caiMoney[i]+like[i]);
                }
                System.out.print("请选择您要点的菜品编号:");
                int chooseDish = input.nextInt();
                if (chooseDish>3||chooseDish<0){
                    System.out.println("输入错误");
                    return;
                }
                System.out.print("请选择您需要的份数:");
                int number = input.nextInt();
                double deliCharge = 0;
                for (int i = 0; i < dishMegs.length; i++) {
                    if (dishMegs[i] ==null){
                        dishMegs[i] = caiName[chooseDish-1]+" "+number+"份";
                        sumPrices[i] = caiMoney[chooseDish - 1] * number; //计算订单金额
                        deliCharge = (sumPrices[i] >= 50) ? 0 : 5;// 计算送餐费

                    }
                }
                System.out.println("餐费：" + sumPrices[chooseDish-1] + "元，送餐费" + deliCharge + "元，总计："+ (sumPrices[chooseDish-1] + deliCharge) + "元。");
                System.out.println("输入0返回");
                choose = input.nextInt();
                if (choose<1||choose>6)continue;
            } else if (choose == 2) {
                System.out.println("***查看餐袋***");
                System.out.println("序号\t订餐人\t餐品信息\t\t送餐时间\t送餐地址\t总金额\t订单状态");
                for (int i = 0; i < names.length; i++) {
                    if (names[i]==null)break;
                    System.out.println((i+1)+"\t"+names[i]+"\t\t"+dishMegs[i]+"\t"+times[i]+"\t\t"+addresses[i]+"\t"+sumPrices[i]+"\t"+states[i]);
                }
                System.out.println("输入0返回");
                choose = input.nextInt();
                if (choose<1||choose>6)continue;
            } else if (choose == 3) {
                System.out.println("***签收订单***");
                System.out.print("请输入要签收的订单");
                int num = input.nextInt();
                if (num>names.length||num<0){
                    System.out.println("输入错误，订单签收失败");
                    continue;
                }
                if (names[num-1]!=null&&states[num-1]==0){
                    states[num-1] =1;
                    System.out.println("订单签收成功");
                }else {
                    System.out.println("订单签收失败");
                    continue;
                }
            } else if (choose == 4) {
                System.out.println("***删除订单***");
                System.out.print("请输入要删除的订单序号");
                int delete = input.nextInt();
                if (names[delete-1]!=null&&states[delete-1]==1){
                    for(int j=delete-1;j<names.length-1;j++){
                        names[j] = names[j+1];
                        dishMegs[j] = dishMegs[j+1];
                        times[j] = times[j+1];
                        addresses[j] = addresses[j+1];
                        states[j] = states[j+1];
                        sumPrices[j] = sumPrices[j+1];
                    }
                    names[names.length-1] = null;
                    dishMegs[names.length-1] = null;
                    times[names.length-1] = 0;
                    addresses[names.length-1] = null;
                    states[names.length-1] = 0;
                    System.out.println("订单删除成功");
                }
                System.out.println("输入0返回");
                choose = input.nextInt();
                if (choose<1||choose>6)continue;
            } else if (choose == 5) {
                System.out.println("我要点赞");
                for (int i = 0; i < caiName.length; i++) {
                    System.out.println((i+1)+caiName[i]+caiMoney[i]+like[i]);
                }
                System.out.print("请选择您要点的菜品编号:");
                int like0 = input.nextInt();
                if (like0>3||like0<0) {
                    System.out.println("输入错误");
                    return;
                }else {
                    like[like0-1]++;
                }

            } else if (choose == 6) {
                break;
            }
        }
        System.out.println("谢谢使用，欢迎下次光临");
    }
}
